package com.huike.business.service.impl;


import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.clues.service.ISysDictDataService;
import com.huike.common.utils.SecurityUtils;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 *
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {
    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;
    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 新增商机跟进记录
     *
     * @param businessTrackVo 传来的参数
     */
    @Override
    public void addBusiness(BusinessTrackVo businessTrackVo) {
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtils.copyProperties(businessTrackVo, tbBusiness);
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        String createBy = SecurityUtils.getUsername();
        String expectedSalary = businessTrackVo.getExpectedSalary();
        String falseReason1 = "reasons_for_business_reporting";
        String falseReason = sysDictDataService.selectDictLabel(falseReason1, expectedSalary);
        tbBusinessTrackRecordMapper.addBusiness(businessTrackVo, createBy, falseReason);
    }

    /**
     * 查询商机跟进
     *
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> list(Long id) {
        List<TbBusinessTrackRecord> list;
        list = tbBusinessTrackRecordMapper.select(id);
        for (TbBusinessTrackRecord businessTrackRecord : list) {
            String username = SecurityUtils.getUsername();
            businessTrackRecord.setCreateBy(username);
        }
        return list;
    }
}
